package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.ExamInfo;
import com.training.content.service.IExamInfoService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 试卷信息Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/exam/info")
public class ExamInfoController extends BaseController
{
    @Autowired
    private IExamInfoService examInfoService;

    /**
     * 查询试卷信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamInfo examInfo)
    {
        startPage();
        List<ExamInfo> list = examInfoService.selectExamInfoList(examInfo);
        return getDataTable(list);
    }

    /**
     * 导出试卷信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:info:export')")
    @Log(title = "试卷信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ExamInfo examInfo)
    {
        List<ExamInfo> list = examInfoService.selectExamInfoList(examInfo);
        ExcelUtil<ExamInfo> util = new ExcelUtil<ExamInfo>(ExamInfo.class);
        return util.exportExcel(list, "试卷信息数据");
    }

    /**
     * 获取试卷信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:info:query')")
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") Long examId)
    {
        return AjaxResult.success(examInfoService.selectExamInfoByExamId(examId));
    }

    /**
     * 新增试卷信息
     */
    @PreAuthorize("@ss.hasPermi('exam:info:add')")
    @Log(title = "试卷信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamInfo examInfo)
    {
        return toAjax(examInfoService.insertExamInfo(examInfo));
    }

    /**
     * 修改试卷信息
     */
    @PreAuthorize("@ss.hasPermi('exam:info:edit')")
    @Log(title = "试卷信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamInfo examInfo)
    {
        return toAjax(examInfoService.updateExamInfo(examInfo));
    }

    /**
     * 删除试卷信息
     */
    @PreAuthorize("@ss.hasPermi('exam:info:remove')")
    @Log(title = "试卷信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Long[] examIds)
    {
        return toAjax(examInfoService.deleteExamInfoByExamIds(examIds));
    }
}
